Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v11.7.1 cherrypick: Fix CurrencyRateController starting in background (#22326) #22327

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Dec 18, 2023

Description

Cryptocompare reported a spike in API requests. This is the result of incorrectly starting CurrencyRateController polling on MetaMask extension background startup. This PR fixes the issue by removing the logic that was starting CurrencyRateController polling in the constructor.

Related issues

Fixes: #21549

Manual testing steps

  1. Open network debug on background.html
  2. Restart extension
  3. No cryptocompare requests should be seen
  4. Open wallet UI
  5. One cryptocompare request should be seen
  6. Wait 3mins
  7. Another cryptocompare request should be seen
  8. Close UI
  9. Wait 3mins
  10. No additional cryptocompare requests should be seen

Screenshots/Recordings

Before

Note the requests made before the UI is open, but that they are stopped after UI is opened then closed for the first time.

Screen.Recording.2023-12-18.at.9.45.07.AM.mov

After

Screen.Recording.2023-12-18.at.9.43.25.AM.mov

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
  • In case it's "ready for review", I've changed it from "draft" to "non-draft".

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Description

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

DDDDDanica and others added 5 commits December 15, 2023 18:36
When a user adds a chain from a dapp, they will see warnings that the
currency symbol is incorrect, even though it is correct.

Part of the problem was that the `pendingConfirmation` variable inside
of `fetchSafeChainsList` was undefined when it should not be. I guess it
closed over the original value or something like that? I didn't verify.
This PR corrects it by explictly passing the updated
`pendingConfirmations` variable to `fetchSafeChainList`

The other problem was that `useAlertState` was calling
`getTemplateAlerts` twice, without resetting the alert state. On the
first call, alerts were being set in state because the request to
chainId.network had not yet resolved. This PR fixes it by ensuring that
that `useAlertState` does not call `getTemplateAlerts` before the fetch
to chainId.network has resolved (when this confrimation type is an add
ethereum chain approval)

An example of the problem can be seen by going to
https://chainlist.org/?search=cro and adding Cronos Mainnet to metamask,
only to see warnings that the currency symbol is incorrect even though
it is correct.

![Screenshot from 2023-12-15
18-26-51](https://github.com/MetaMask/metamask-extension/assets/7499938/80e299d4-1545-4a38-981f-8b1eafc0b3dc)

1. Go to https://chainlist.org/?search=cro
2. Add Cronos mainnet to metamask
3. The confirmation window should open with an add ethereum chain
confirmation. There should be no warnings
4. Reject the confirmation
5. Open the dev console and paste the below code, and press enter. The
confirmation window should open with an add ethereum chain confirmation.
There should be warnings about the currency symbol
6. Reject the confirmation
7. Modify the below code so that `"symbol": "cra",` becomes `"symbol":
"cro",`, paste it in the dev console and press enter. There should be no
warnings in the new confirmation window

```
await window.ethereum.request({
  "method": "wallet_addEthereumChain",
  "params": [
    {
      "blockExplorerUrls": [
        "https://blockscout.com/poa/xdai/"
      ],
      "nativeCurrency": {
        "name": "CRO",
        "symbol": "cra",
        "decimals": 18
      },
      "rpcUrls": [
        "https://evm.cronos.org",
        null
      ],
      "chainId": "0x19",
      "chainName": "Cronos Mainnet"
    }
  ]
});
```

https://github.com/MetaMask/metamask-extension/assets/7499938/d6f738be-8e4a-4618-8703-c2d94df9c8a7

https://github.com/MetaMask/metamask-extension/assets/7499938/c3ab5cf6-ac73-4ad3-b7b3-fd49910c0311

<!-- [screenshots/recordings] -->

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Pedro Figueiredo <[email protected]>
We want a ChainID: Ticker Map for future validation on some of our more
commonly used networks. This PR adds that mapping constant, changes
Optimism's "OP" ticker to "ETH" and fixes a resulting unit test failure.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

Fixes: [#1708
](MetaMask/MetaMask-planning#1708)

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

<!-- [screenshots/recordings] -->

<!-- [screenshots/recordings] -->

- [X] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [X] I've clearly explained what problem this PR is solving and how it
is solved.
- [X] I've linked related issues
- [X] I've included manual testing steps
- [X] I've included screenshots/recordings if applicable
- [X] I’ve included tests if applicable
- [X] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [X] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [X] I’ve properly set the pull request status:
  - [X] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Dan J Miller <[email protected]>
…2307)

During the backup flow, we should prompt a user for a password. This
provides extra friction during a security sensitive step.

1. Build, install and onboard
2. Make sure to back up your seed phrase during onboarding. Onboarding
should work as normal
3. Once you get to the home screen, replace `home.html` in the url
browsers url bar with
`home.html#onboarding/secure-your-wallet/?isFromReminder=true` and press
enter
4. Click "Secure my wallet"
5. You should then be prompted to enter your password.
6. After entering your password, you should be able to proceed as normal

If you repeat those steps but click cancel when being prompted to enter
your password, you should be taken to the home screen.

If you repeat those steps, but on step 2 don't back up your seed phrase,
the remaining steps should work as described above.

https://github.com/MetaMask/metamask-extension/assets/7499938/ac8b5dfb-ca7b-4622-95b8-07db5405abfe

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Pedro Figueiredo <[email protected]>
@jiexi jiexi requested a review from a team as a code owner December 18, 2023 18:29
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@jiexi jiexi requested a review from danjm December 18, 2023 18:30
@jiexi jiexi requested review from a team as code owners December 18, 2023 18:38
@jiexi jiexi force-pushed the jl/Version-v11.7.1-cherry-pick-currencyRateController-fix branch from 7570b05 to 92545de Compare December 18, 2023 19:02
@jiexi jiexi closed this Dec 18, 2023
@jiexi jiexi deleted the jl/Version-v11.7.1-cherry-pick-currencyRateController-fix branch December 18, 2023 19:03
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2023
@jiexi
Copy link
Contributor Author

jiexi commented Dec 18, 2023

Rebased here #22328

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants